<?php
/**
 * 获取天气接口
 * @author Bigface <saybye720@gmail.com> 82220797@qq.com
 * @copyright Copyright (c) 2009-2012 bigface.cc
 * @license http://blog.bigface.cc
 * @version $Id: weather.php 2012-07-20$
 */
defined("BFCMS") or exit("No permission resources.");
function getWeather($cityname,$days){
        $content = file_get_contents("http://www.google.com/ig/api?weather=" . $cityname . "&hl=zh-cn");
        $content = mb_convert_encoding($content, "UTF-8", "GBK");
        $xml = simplexml_load_string($content);
        if($days>4){
                echo "最多只能获取4天的天气";
                return false;
        }
        if($days=1){//获取当天天气情况
                //获得准确天气情况对象
                $current = $xml->weather->current_conditions;
                $condition = (array) $current->condition; //天气情况
                $icon = (array) $current->icon; //当前天气情况图片
                //获取今天的最高温度和最低温度
                $tadaytq = $xml->weather->forecast_conditions;
                $low_temp = (array) $tadaytq->low;
                $high_temp = (array) $tadaytq->high;
                $weather = array('low_temp' => $low_temp['@attributes']['data'], 'high_temp' => $high_temp['@attributes']['data'], 'icon' => $icon['@attributes']['data']);
                return $weather;
        }
}
//test by bigface
//$wea=  getWeather("jinan", 1);
//print_r($wea);
?>

